package com.example.keli.base.utils;

import android.content.Context;
import android.support.annotation.NonNull;

import com.yanzhenjie.album.Action;
import com.yanzhenjie.album.Album;
import com.yanzhenjie.album.AlbumFile;
import com.yanzhenjie.album.Filter;

import java.util.ArrayList;

/**
 * Description:
 * Data：2019/3/25-17:05
 * Author: Allen
 */
public class AlbumUtil {
    public static void getImages(Context context,int maxCount, Action<ArrayList<AlbumFile>> action) {
        Album.image(context) // Image selection.
                .multipleChoice()
                .camera(true)
                .columnCount(3)
                .selectCount(maxCount)
                .onResult(action)
                .onCancel(new Action<String>() {
                    @Override
                    public void onAction(@NonNull String result) {
                    }
                })
                .start();
    }

    public static void recordVideo(Context context,long maxDuration, Action<String> action) {
        Album.camera(context)
                .video() // Record Video.
                .quality(1) // Video quality, [0, 1].
                .limitDuration(maxDuration) // The longest duration of the video is in milliseconds.
                .limitBytes(Long.MAX_VALUE) // Maximum size of the video, in bytes.
                .onResult(action)
                .onCancel(new Action<String>() {
                    @Override
                    public void onAction(@NonNull String result) {
                    }
                })
                .start();
    }

    public static void getVideos(Context context,final long maxDuration, Action<ArrayList<AlbumFile>> action) {
        Album.video(context) // Video selection.
                .multipleChoice()
                .camera(true)
                .columnCount(2)
                .selectCount(1)
                .filterDuration(new Filter<Long>() {
                    @Override
                    public boolean filter(Long attributes) {
                        return attributes > maxDuration;
                    }
                })
                .onResult(action)
                .onCancel(new Action<String>() {
                    @Override
                    public void onAction(@NonNull String result) {
                    }
                })
                .start();
    }
}
